﻿<!DOCTYPE HTML>
<html>
<head>
	<meta charset="utf-8">
	<meta name="renderer" content="webkit|ie-comp|ie-stand">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
	<meta http-equiv="Cache-Control" content="no-siteapp" />
	<link rel="Bookmark" href="/admin/imgs/logo.ico"/>
	<link rel="Shortcut Icon" href="/admin/imgs/logo.ico"/>
	<link rel="stylesheet" type="text/css" href="static/h-ui/css/H-ui.min.css" />
	<link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/H-ui.admin.css" />
	<link rel="stylesheet" type="text/css" href="lib/Hui-iconfont/1.0.8/iconfont.css" />
	<link rel="stylesheet" type="text/css" href="static/h-ui.admin/skin/default/skin.css" id="skin" />
	<link rel="stylesheet" type="text/css" href="static/h-ui.admin/css/style.css" />
	<title>系统后台</title>
	<link href="lib/webuploader/0.1.5/webuploader.css" rel="stylesheet" type="text/css" />

	<script type="text/javascript" src="lib/jquery/1.9.1/jquery.min.js"></script>
	<script type="text/javascript" src="js/admin.js"></script>
	<script type="text/javascript">
		var info = getLoginInfo();
		(function(){
			if (!info) {
				window.location.href = 'login.html';
			}
		})();
	</script>
</head>
<body>
<section class="Hui-article-box" style="position:relative;top:0;left:0;">
	<nav class="breadcrumb" style="color:#888;">
		<!--<i class="Hui-iconfont">&#xe67f;</i> -->
		<!--<a href="main.html" class="maincolor">首页</a>-->
		<!--<span class="c-gray en">&gt;</span>-->
		<!--权限管理-->
		<!--<span class="c-gray en">&gt;</span>-->
		<!--功能列表-->
		<!--<span class="c-gray en">&gt;</span>-->
		<!--新增-->
	</nav>
</section>
<div class="page-container" style="margin:10px 10%;width:50%;position:relative;top:50px;left:0;">
	<input type="hidden" id="id" value="">
	<div class="row cl" style="margin-bottom:20px;">
		<label class="form-label col-xs-4 col-sm-3">
			<span class="c-red">*</span>功能名称：
		</label>
		<div class="formControls col-xs-8 col-sm-9">
			<input type="text" class="input-text" value="" placeholder="功能名" id="name">
		</div>
	</div>
	<div class="row cl" style="margin-bottom:20px;">
		<label class="form-label col-xs-4 col-sm-3">
			<span class="c-red">*</span>父级：
		</label>
		<div class="formControls col-xs-8 col-sm-9"> 
			<span class="select-box">
				<select class="select" id="pid"></select>
			</span> 
		</div>
	</div>
	<div class="row cl" style="margin-bottom:20px;">
		<label class="form-label col-xs-4 col-sm-3">
			<span class="c-red">*</span>地址链接：
		</label>
		<div class="formControls col-xs-8 col-sm-9">
			<input type="text" class="input-text" value="" placeholder="地址链接" id="link">
		</div>
	</div>
	<div class="row cl">
		<div class="col-xs-8 col-sm-9 col-xs-offset-4 col-sm-offset-2">
			<button onClick="save()" class="btn btn-secondary radius" type="button">保存</button>
			<button onClick="back()" class="btn btn-default radius" type="button"> &nbsp; 取消 &nbsp; </button>
		</div>
	</div>
</div>

<span id="pop"></span>
</body>
</html>

<script type="text/javascript">
	var id = getParamByUrl('id');
	var name = getParamByUrl('name');
	var link = getParamByUrl('link');
	var pid = getParamByUrl('pid');
	(function(){
		getCrumbs({id:1,sub:2}); //面包屑
		$('#id')[0].value = id;
		$('#name')[0].value = name;
		$('#link')[0].value = link;
		getListByPid();
	})();
	function getListByPid(){
		$.ajax({
			type: 'post',
			url: domain+'menu/listbypid',
			data: {},
			success: function (res) {
				res = JSON.parse(res);
				console.log(res);
				if (res.code!=0) {
					console.log({msg:res.msg}); return
				}
				var d = res.data;
				var h = '';
				for (var i=0; i<d.length; i++) {
					h += '<option value="'+d[i].id+'" ';
					console.log(d[i].id,pid);
					if (d[i].id==pid) { h += ' selected'; }
					h += '>';
					h += d[i].title;
					h += '</option>';
					h += '';
				}
				$('#pid').html(h);
			},
			error: function () {
				console.log('网络异常');
			}
		});
	}
	function save(){
		var name = $('#name').val();
		var link = $('#link').val();
		var pid = $('#pid').val();
		if (!name) {
			pop({msg:'管理员名必填'}); return
		}
		if (pid>0 && !link) {
			pop({msg:'地址必填'}); return
		}
		var formData = {
			id: id, name: name, link: link, pid: pid
		};
		// console.log(formData); return
		$.ajax({
			type: "POST",
			url: domain+'menu/modify',
			data: formData,
			success: function (res) {
				res = JSON.parse(res);
				console.log(res);
				if (res.code!=0) {
					pop({msg:res.msg}); return
				}
				pop({msg:'成功'});
				setTimeout(function(){
					window.location.href = 'menu.html';
				},2000);
			},
			error: function (XMLHttpRequest, textStatus, errorThrown) {
				console.log('网络异常');
				pop({msg:'网络异常'});
			}
		});
	}
	function back(){
		window.location.href = 'menu.html';
	}
</script>